﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Diagnostics;

namespace BaGiaDanhCuop
{
    public class Guy
    {
        public Texture2D move, mid, strong, weapon, shadow;
        public Animation move_ani, mid_ani, strong_ani, weapon_ani;
        public Rectangle rectangle;
        public Vector2 position;
        public int state;

        public Guy(Texture2D move, Texture2D mid, Texture2D strong, Texture2D weapon, Texture2D shadow, int state)
        {
            
            this.move = move;
            this.mid = mid;
            this.strong = strong;
            this.weapon = weapon;
            this.shadow = shadow;

            position = new Vector2(850, 470 - move.Height);
            rectangle = new Rectangle(0, 0, move.Width / 6, move.Height);

            move_ani = new Animation(position, move, new Microsoft.Xna.Framework.Point(6, 1));
            move_ani.animate(0.2f);
            mid_ani = new Animation(position, mid, new Microsoft.Xna.Framework.Point(6, 1));
            mid_ani.animate(0.2f);
            strong_ani = new Animation(position, strong, new Microsoft.Xna.Framework.Point(2, 1));
            strong_ani.animate(0.2f);
            weapon_ani = new Animation(position, weapon, new Microsoft.Xna.Framework.Point(6, 1));
            weapon_ani.animate(0.2f);

            this.state = state;
        }

        public Guy GetGuy()
        {
            return new Guy(this.move, this.mid, this.strong, this.weapon, this.shadow, this.state);
        }

        public void Update(float deltatime)
        {
            switch (state)
            {
                case GamePage.STATE_MOVE:
                    move_ani.Update(deltatime);
                    move_ani.Offset.X -= 150 * deltatime;
                    position.X -= 150 * deltatime;
                    break;
                case GamePage.STATE_MID:
                    mid_ani.Update(deltatime);
                    mid_ani.Offset.X -= 150 * deltatime;
                    position.X -= 150 * deltatime;
                    break;
                case GamePage.STATE_STRONG:
                    if (strong_ani.FrameIndex < 1)
                    {
                        strong_ani.Update(deltatime);
                    }
                    strong_ani.Offset.X -= 100 * deltatime;
                    strong_ani.Offset.Y = 470 - strong.Height;
                    position.X -= 100 * deltatime;
                    break;
                case GamePage.STATE_WEAPON:
                    move_ani.Update(deltatime);
                    weapon_ani.Update(deltatime);
                    move_ani.Offset.X -= 150 * deltatime;
                    weapon_ani.Offset.X -= 150 * deltatime;
                    position.X -= 150 * deltatime;
                    break;
            }
        }

        public bool ColletionStick()
        {

        }

        public int ColletionWoman(Stick stick)
        {
            if (stick.state == GamePage.STATE_MID
                && this.position.X < stick.position.X + stick.Fighting_Mid_Animation.FrameSize.X 
                && this.position.X + this.move_ani.FrameSize.X > stick.position.X
                && this.position.Y < stick.position.Y + stick.Fighting_Mid_Animation.FrameSize.Y
                && this.position.Y + this.move_ani.FrameSize.Y > stick.position.Y)
            {
                state = GamePage.STATE_MID;
                mid_ani.Offset.X = this.position.X;
                return GamePage.STATE_MID;
            }
            else if (stick.state == GamePage.STATE_STRONG
               && this.position.X < stick.position.X + stick.Fighting_Mid_Animation.FrameSize.X
               && this.position.X + this.move_ani.FrameSize.X > stick.position.X
               && this.position.Y < stick.position.Y + stick.Fighting_Mid_Animation.FrameSize.Y
               && this.position.Y + this.move_ani.FrameSize.Y > stick.position.Y)
            {
                state = GamePage.STATE_STRONG;
                strong_ani.Offset.X = this.position.X;
                return GamePage.STATE_STRONG;
            }
            return GamePage.STATE_FAIL;
        }

        public void Draw(SpriteBatch batch)
        {
            switch (state)
            {
                case GamePage.STATE_MOVE:
                    batch.Draw(shadow, new Vector2(position.X + 10, 450), Color.White);
                    move_ani.Draw(batch, SpriteEffects.None);
                    break;
                case GamePage.STATE_MID:
                    batch.Draw(shadow, new Vector2(position.X + 10, 450), Color.White);
                    mid_ani.Draw(batch, SpriteEffects.None);
                    break;
                case GamePage.STATE_STRONG:
                    //batch.Draw(shadow, new Vector2(position.X + 10, 450), Color.White);
                    strong_ani.Draw(batch, SpriteEffects.None);
                    break;
                case GamePage.STATE_WEAPON:
                    batch.Draw(shadow, new Vector2(position.X + 10, 450), Color.White);
                    move_ani.Draw(batch, SpriteEffects.None);
                    weapon_ani.Draw(batch, SpriteEffects.None);
                    break;
            }
        }

    }
}
